package com.xxw.yygh.hosp.controller.api;

import com.xxw.yygh.hosp.bean.Result;
import com.xxw.yygh.hosp.service.DepartmentService;
import com.xxw.yygh.hosp.utils.HttpRequestHelper;
import com.xxw.yygh.model.hosp.Department;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {

    @Resource
    private DepartmentService departmentService;


    //新增科室
    @PostMapping("/saveDepartment")
    public Result saveDepartment(HttpServletRequest request){
        Map<String, Object> resultMap = HttpRequestHelper.switchMap(request.getParameterMap());

        departmentService.savaDepartment(resultMap);
        return Result.ok();
    }

    //查询科室信息
    @PostMapping("/department/list")
    public Result<Page> getDepartmentPage(HttpServletRequest request){
        Map<String, Object> resultMap = HttpRequestHelper.switchMap(request.getParameterMap());
        Page<Department> page=departmentService.getDepartmentPage(resultMap);
        return Result.ok(page);
    }

    //删除科室
    @PostMapping("/department/remove")
    public Result remove(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        departmentService.remove(stringObjectMap);
        return Result.ok();

    }

}
